package com.zhongfl.crm.lixiao.bean.resolve;

import com.heptagram.lixiao.bean.response.lead.LXLead;
import com.zhongfl.crm.model.LxUser;
import com.zhongfl.crm.service.LxUserService;
import tech.heptagram.channel.api.model.Channel;

import java.util.Objects;

/**
 * LeadModelResolver 服务类
 *
 * @author tiantian
 * @date 2018/7/11 21:50
 */
public class LeadModelResolver implements ModelResolver<Channel, LXLead.DataResult> {

    private LxUserService lxUserService;

    public LeadModelResolver(LxUserService lxUserService) {
        this.lxUserService = lxUserService;
    }

    @Override
    public Channel resolve(LXLead.DataResult lead) throws ModelResolverException {
        Channel channel = new Channel();

        channel.setContactsName(lead.getName());
        channel.setContactsMobile(lead.getAddress().getPhone());
        channel.setChannelName(lead.getCompanyName());
        channel.setAddress(lead.getAddress().getDetailAddress());
        channel.setType("LEAD");
        channel.setLxLeadId(lead.getId());
        //channel.setLxCustomerId();
        channel.setCreatedBy("BOSS系统");
        channel.setCreatedTime(lead.getCreatedAt());
        channel.setModifiedBy("BOSS系统");
        channel.setModifiedTime(lead.getUpdatedAt());

        LxUser lxUser = lxUserService.findByLxId(lead.getCreator().getId());
        if (Objects.nonNull(lxUser)) {
            channel.setStaffName(lxUser.getStaffName());
            channel.setStaffCode(lxUser.getStaffCode());
        }

        return channel;
    }
}
